package com.googlecode.jasmincc.framework.namespace.implementation;

import java.io.*;
import com.googlecode.jasmincc.framework.io.*;
import com.googlecode.jasmincc.framework.namespace.Namespace;
import com.googlecode.jasmincc.framework.services.*;

public class SimpleNamespaceFactory implements NamespaceFactory {
	private static SimpleNamespaceFactory instance = new SimpleNamespaceFactory();

	protected DirectoryBuilder directoryBuilder = null;

	protected FilenameFilter fileNameFilter = null;

	protected GetGrammarNameByFile getGrammarNameByFile = null;

	public SimpleNamespaceFactory() {

	}

	public static SimpleNamespaceFactory getInstance() {
		return instance;
	}

	public Namespace getNamespace(String name) throws Exception {
		Namespace namespace = new Namespace(name);
		namespace.setDirectoryBuilder(directoryBuilder);
		namespace.setFileNameFilter(fileNameFilter);
		namespace.setGetGrammarNameByFile(getGrammarNameByFile);
		namespace.init();
		return namespace;
	}

	/**
	 * @param directoryBuilder the directoryBuilder to set
	 */
	public void setDirectoryBuilder(DirectoryBuilder directoryBuilder) {
		this.directoryBuilder = directoryBuilder;
	}

	/**
	 * @param filenameFilter the filenameFilter to set
	 */
	public void setFileNameFilter(FilenameFilter fileNameFilter) {
		this.fileNameFilter = fileNameFilter;
	}

	/**
	 * @param getGrammarNameByFile the getGrammarNameByFile to set
	 */
	public void setGetGrammarNameByFile(GetGrammarNameByFile getGrammarNameByFile) {
		this.getGrammarNameByFile = getGrammarNameByFile;
	}
}
